package communicationMessages;

import data.MemberDataBase;

public class LoginMessage extends Message {

	@Override
	public String getAnswer() {
		System.out.println("someone try to login");
		String ans;
		String userName,password;
		String arr[] = this.getContent().split("\n");
		if (arr.length == 2)
		{
			userName = arr[0];
			password = arr[1];
		}
		else
		{
			ans = "wrong format\n";
			System.out.println("failed format");
			return ans;
		}
		MemberDataBase uDataBase = MemberDataBase.getMembersDataBase();
		if (uDataBase.authenticate(userName, password))
		{
			ans="login\nsuccess\n";
			System.out.println("sucsses");
			uDataBase.addLoginMember(uDataBase.getMember(userName));
		}
		else
		{
			System.out.println("failed user name password");
			ans = "login\nfailed\nwrong user or password\n";
		}
		return ans;
	}

}
